import { setToken, getToken, delToken } from '@/utils/stroage'
import { userLogin, sendSms } from '@/api/user'
export default {
  namespaced: true,
  state: {
    token: getToken() || '',
    user: {}
  },
  mutations: {
    setToken (state, payload) {
      state.token = payload
      setToken(payload)
    },
    delToken (state) {
      state.token = ''
      delToken()
    },
    delUser (state) {
      state.user = null
    },
    setUser (state, payload) {
      state.user = payload
    }
  },
  actions: {
    async userLogin (context, payload) {
      const res = await userLogin(payload)
      console.log(res, '获取token')
      context.commit('setToken', res.data.token)
    },
    async logout (context) {
      context.commit('delToken')
      context.commit('delUser')
    },
    async userSms (context, payload) {
      await sendSms(payload)
    }
  }
}
